import React, { Component } from 'react'
import {Switch,Route,Redirect} from 'react-router-dom'


export default class RouterView extends Component {
    render() {
        let compList=this.props.routes.filter((item)=>item.path);
        let redirectList=this.props.routes.filter((item)=>item.to)
        return (
          
            <Switch>
                {compList.map((v,i)=>{
                    return <Route key={i} render={(props)=>{
                       return  <v.component routes={v.children || []} {...props}></v.component>
                    }} path={v.path}></Route>
                })}

                {redirectList.map((v,i)=>{
                    return <Redirect from={v.from} to={v.to} key={i}></Redirect>
                })}


            </Switch>
         
            
        )
    }
}
